package com.jzo2o.customer.controller.agency;

import com.jzo2o.customer.model.domain.BankAccount;
import com.jzo2o.customer.model.dto.response.BankAccountResDTO;
import com.jzo2o.customer.service.BankAccountService;
import com.jzo2o.mvc.utils.UserContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController("agencyBankAccountController")
@RequestMapping("/agency/bank-account")
@Api(tags = "机构端 - 银行账户")
public class BankAccountController {
    @Resource
    private BankAccountService bankAccountService;

    @PostMapping
    @ApiOperation("新增或更新银行账号信息")
    public BankAccount addOrUpdate(@RequestBody BankAccountResDTO bankAccountReqDTO) {
        BankAccount byId = bankAccountService.getById(UserContext.currentUserId());
        if(byId == null){
            // 新增
            return bankAccountService.addBankAgency(bankAccountReqDTO);
        }else {
            // 更新
            return bankAccountService.updateBankAgency(bankAccountReqDTO);
        }
    }

    @GetMapping(path = "/currentUserBankAccount")
    @ApiOperation("获取当前用户银行账号")
    public BankAccount getUserBankAccount() {
        return bankAccountService.getUserBankAccount();
    }
}
